<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="./js/jquery-1.11.1.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/main.js"></script>
    <style type="text/css">
        body {
            background: #2fb9e2;
        }
        
        .panel {
            margin: auto;
            margin-top: 200px;
            padding: 10%;
            padding-top: 2%;
            width: 500px;
            height: 400px;
            background-color: #fff;
            border-radius: 20px;
            box-shadow: 0px 0px 20px #5b7884;
        }
        
        #logo {
            margin-top: 30px;
            margin-bottom: 40px;
            text-align: center
        }
        
        #submit {
            width: 100px;
            margin: auto;
            margin-top: 50px;
        }

    </style>

</head>
<script>
    $(document).ready(function() {
        $("#submit").click(function() {
            var name = $("#username").val();
            var pwd = $("#password").val();
            //alert(name + "," + pwd);
            if (!checkInput("密码" , pwd) || !checkInput("姓名" , name)) {
                return
            }
            
            var settings = {
                type: "POST",
                url: "../../Fanxiangle/servlet/manager",
                dataType: "json",
                data: {
                    module: "admin",
                    action: "login",
                    username: name,
                    password: pwd
                },
                error: function(XHR, textStatus, errorThrown) {
                    alert("网络错误");
                },
                success: function(data, textStatus) {
                    if (textStatus == "success") {
                        if (data.status == true) {
                            //alert("操作成功")
                            var aid = getCookie('aid')
                            if (!aid || aid != data.data.aid) {
                                setCookie('aid', data.data.aid, 1)
                            }
                            var username = getCookie('username')
                            if (!username || username != data.data.username) {
                                setCookie('username', data.data.username, 1)
                            }
                            var sessionid = getCookie('sessionid');
                            if(!sessionid || sessionid != data.data.sessionid) {
                                setCookie('sessionid',data.data.sessionid,1)
                            }
                            //tiaozhuan
                            window.location.href = "manage.html"
                        } else if (data.errorCode == 1001) {
                            alert("参数不全")
                        } else if (data.errorCode == 1011) {
                            alert("密码错误")
                        } else if (data.errorCode == 1012) {
                            alert("用户不存在")
                        } else if (data.errorCode == 1000) {
                            alert("未知错误")
                        }
                        //alert("data:" + data.data.aid + ",status:" + textStatus)
                    }

                },
            };
            $.ajax(settings);
        });
    });


</script>

<body>
    <div class="container">
        <div class="panel">
            <h1 id="logo">饭享乐<small>-管理</small></h1>
            <form>
                <input type="hidden" name="module" value="admin">
                <input type="hidden" name="action" value="login">
                <div class="form-group">
                    <label for="username">用户名</label>
                    <input type="text" class="form-control" id="username" name="username" placeholder="用户名">
                </div>
                <div class="form-group">
                    <label for="password">密码</label>
                    <input type="password" class="form-control" id="password" name="password" placeholder="密码">
                </div>
                <button type="button" class="btn btn-primary btn-block" id="submit">提交</button>
            </form>

        </div>
    </div>

</body>

</html>

